// 在此处对axios做集中配置
import axios from "axios"; //引入axios

const instance = axios.create({
  baseURL: "https://0vr23bmq.lc-cn-n1-shared.com/1.1", //接口地址中，每个接口都一样的部分
  headers: {
    "X-LC-Id": "0Vr23bmqBOZGNQpx32ltkZA9-gzGzoHsz",
    "X-LC-Key": "5BFQAdjOVm71iPdUJGHWHyJN",
    "Content-Type": "application/json",
  }, //配置请求头,携带验证信息给后端
});

// 添加响应拦截器
instance.interceptors.response.use(
  function (response) {
    if (response.status == 200) {
      // ElMessage({
      //   message: "登录成功",
      //   type: "success",
      // });
    }
    return response;
  },
  function (error) {
    // console.log(error);
    if (error.response.data.code == 210) {
      ElMessage({
        message: "用户名或密码错误",
        type: "warning",
      });
    }
    if (error.response.data.code == 219) {
      ElMessage({
        message: "登录失败次数超过限制,请稍候再试",
        type: "error",
      });
    }
    return Promise.reject(error);
  }
);

export default instance; //配置后的axios
